#include "Date.h"


void Date::Print() const
{
	cout << _year << "/" << _month << "/" << _day << endl;
}

Date& Date::operator+=(int day)
{
	if (day < 0)
	{
		return *this -= (-day);
	}
	_day += day;
	int curday = GetMonthDay(_year, _month);
	while (_day > curday)
	{
		_day -= curday;
		_month++;
		if (_month > 13)
		{
			_month = 1;
			_year++;
		}
		curday = GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator+(int day) const
{
	//Date tmp(*this);
	//tmp._day += day;
	//int curday = GetMonthDay(tmp._year, tmp._month);
	//while (tmp._day > curday)
	//{
	//	tmp._day -= curday;
	//	tmp._month++;
	//	if (tmp._month > 13)
	//	{
	//		tmp._month = 1;
	//		tmp._year++;
	//	}
	//	curday = GetMonthDay(tmp._year, tmp._month);
	//}
	//return tmp;

	Date tmp(*this);
	tmp += day;
	return tmp;
}

Date& Date::operator++()
{
	*this += 1;
	return *this;
}

Date Date::operator++(int)
{
	Date tmp(*this);
	++(*this);
	return tmp;
}

Date& Date::operator-=(int day)
{
	if (day < 0)
	{
		return *this += (-day);
	}
	_day -= day;
	while (_day <= 0)
	{
		_month--;
		if (_month == 0)
		{
			_month = 12;
			_year--;
		}
		_day += GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator-(int day) const
{
	Date tmp(*this);
	tmp -= day;
	return tmp;
}

Date& Date::operator--()
{
	*this -= 1;
	return *this;
}

Date Date::operator--(int)
{
	Date tmp(*this);
	--(*this);
	return tmp;
}

bool Date::operator<(const Date& d) const
{
	if (_year != d._year) return _year < d._year;
	if (_month != d._month) return _month < d._month;
	if (_day != d._day) return _day < d._day;
	return false;
}

bool Date::operator<=(const Date& d) const
{
	if (_year != d._year) return _year < d._year;
	if (_month != d._month) return _month < d._month;
	if (_day != d._day) return _day < d._day;
	return true;
}

bool Date::operator>(const Date& d) const
{
	if (_year != d._year) return _year > d._year;
	if (_month != d._month) return _month > d._month;
	if (_day != d._day) return _day > d._day;
	return false;
}

bool Date::operator>=(const Date& d) const
{
	if (_year != d._year) return _year > d._year;
	if (_month != d._month) return _month > d._month;
	if (_day != d._day) return _day > d._day;
	return true;
}

bool Date::operator==(const Date& d) const
{
	return _year == d._year && _month == d._month && _day == d._day;
}

bool Date::operator!=(const Date& d) const
{
	return !(*this == d);
}
